/*
	This file is part of the OdinMS Maple Story Server
    Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc> 
                       Matthias Butz <matze@odinms.de>
                       Jan Christian Meyer <vimes@odinms.de>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License version 3
    as published by the Free Software Foundation. You may not use, modify
    or distribute this program under any other version of the
    GNU Affero General Public License.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

package net.sf.odinms.client.messages.commands;

import java.awt.Rectangle;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;

import net.sf.odinms.client.MapleInventoryType;
import net.sf.odinms.client.MapleCharacter;
import net.sf.odinms.client.MapleClient;
import net.sf.odinms.client.MapleInventory;
import net.sf.odinms.client.MapleJob;
import net.sf.odinms.client.MaplePet;
import net.sf.odinms.client.MapleStat;
import net.sf.odinms.client.messages.Command;
import net.sf.odinms.client.messages.CommandDefinition;
import net.sf.odinms.client.messages.IllegalCommandSyntaxException;
import net.sf.odinms.client.messages.MessageCallback;
import net.sf.odinms.database.DatabaseConnection;
import net.sf.odinms.net.channel.ChannelServer;
import net.sf.odinms.scripting.npc.NPCScriptManager;
import net.sf.odinms.server.MapleInventoryManipulator;
import net.sf.odinms.server.MapleItemInformationProvider;
import net.sf.odinms.server.MaplePortal;
import net.sf.odinms.server.MapleShop;
import net.sf.odinms.server.MapleShopFactory;
import net.sf.odinms.server.MapleStatEffect;
import net.sf.odinms.server.TimerManager;
import net.sf.odinms.server.maps.MapleMap;
import net.sf.odinms.server.maps.MapleMist;
import net.sf.odinms.server.maps.SavedLocationType;
import net.sf.odinms.tools.MaplePacketCreator;
import net.sf.odinms.tools.StringUtil;
//import net.sf.odinms.server.MapleStorage;
//import net.sf.odinms.tools.Pair;


public class PlayerCommands implements Command {
    @SuppressWarnings("static-access")
	@Override
	public void execute(MapleClient c, MessageCallback mc, String[] splitted) throws Exception, IllegalCommandSyntaxException {
            final MapleCharacter cc = c.getPlayer();
            if (splitted[0].equals("@spinel")) {
                NPCScriptManager npc = NPCScriptManager.getInstance();
                npc.start(c, 9000020);
            } else if (splitted[0].equals("@random")) {
                String[] wordz = new String[] {"hello","lol","oh","hai","lulz",c.getPlayer().getName(),"obama"};
                int random = 0;
                StringBuilder text = new StringBuilder("[Random]:");
                for (int i = 0; i < wordz.length; i++) {
                    random = (getRandom(wordz.length) - 1);
                    text.append(wordz[random] + " ");
                }
                c.getPlayer().getMap().broadcastMessage(MaplePacketCreator.getChatText(c.getPlayer().getId(), text.toString(), false, 0));
            } else if (splitted[0].equals("@clearinv")) {
                if (splitted.length != 2) {
                    mc.dropMessage("eq, use, setup, etc, cash.");
                    return;
                }
                MapleInventoryType type = null;
                boolean all = false;
                if (splitted[1].equals("all"))
                    all = true;
                else if (splitted[1].equals("eq"))
                    type = MapleInventoryType.EQUIP;
                else if (splitted[1].equals("use"))
                    type = MapleInventoryType.USE;
                else if (splitted[1].equals("setup"))
                    type = MapleInventoryType.SETUP;
                else if (splitted[1].equals("etc"))
                    type = MapleInventoryType.ETC;
                else if (splitted[1].equals("cash"))
                    type = MapleInventoryType.CASH;
                else {
                    mc.dropMessage("@clearslot " + splitted[1] + " does not exist!");
                    return;
                }
                if (!all) {
                    for (int i = 0; i < c.getPlayer().getInventory(type).list().size(); i++)
                        if (c.getPlayer().getInventory(type).getItem((byte) i).getQuantity() == 0)
                            MapleInventoryManipulator.removeFromSlot(c, type, (byte) i, c.getPlayer().getInventory(type).getItem((byte) i).getQuantity(), false, true);
                } else {
                    int i = 0;
                    type = MapleInventoryType.EQUIP;
                    for (i = 0; i < c.getPlayer().getInventory(type).list().size(); i++)
                        if (c.getPlayer().getInventory(type).getItem((byte) i).getQuantity() == 0)
                            MapleInventoryManipulator.removeFromSlot(c, type, (byte) i, c.getPlayer().getInventory(type).getItem((byte) i).getQuantity(), false, true);
                    type = MapleInventoryType.USE;
                    for (i = 0; i < c.getPlayer().getInventory(type).list().size(); i++)
                        if (c.getPlayer().getInventory(type).getItem((byte) i).getQuantity() == 0)
                            MapleInventoryManipulator.removeFromSlot(c, type, (byte) i, c.getPlayer().getInventory(type).getItem((byte) i).getQuantity(), false, true);
                    type = MapleInventoryType.SETUP;
                    for (i = 0; i < c.getPlayer().getInventory(type).list().size(); i++)
                        if (c.getPlayer().getInventory(type).getItem((byte) i).getQuantity() == 0)
                            MapleInventoryManipulator.removeFromSlot(c, type, (byte) i, c.getPlayer().getInventory(type).getItem((byte) i).getQuantity(), false, true);
                    type = MapleInventoryType.ETC;
                    for (i = 0; i < c.getPlayer().getInventory(type).list().size(); i++)
                        if (c.getPlayer().getInventory(type).getItem((byte) i).getQuantity() == 0)
                            MapleInventoryManipulator.removeFromSlot(c, type, (byte) i, c.getPlayer().getInventory(type).getItem((byte) i).getQuantity(), false, true);
                    type = MapleInventoryType.CASH;
                    for (i = 0; i < c.getPlayer().getInventory(type).list().size(); i++)
                        if (c.getPlayer().getInventory(type).getItem((byte) i).getQuantity() == 0)
                            MapleInventoryManipulator.removeFromSlot(c, type, (byte) i, c.getPlayer().getInventory(type).getItem((byte) i).getQuantity(), false, true);
                }
                mc.dropMessage(splitted[1] + " slots are cleared");
            } else if (splitted[0].equals("@rebirth")) {
                int negexp;
                if (c.getPlayer().getLevel() >= 200) {
                    c.getPlayer().setLevel(1);
                    c.getPlayer().setReborns(c.getPlayer().getReborns() + 1);
                    c.getPlayer().changeJob(MapleJob.getById(0));
                    negexp = c.getPlayer().getExp();
                    c.getPlayer().gainExp(-negexp, false, false); // Fixes negative exp
                    c.getPlayer().updateSingleStat(MapleStat.EXP, 0);
                } else {
                    mc.dropMessage("You aren't level 200 or higher!");
                }
            } else if (splitted[0].equals("@cody")) {
                NPCScriptManager npc = NPCScriptManager.getInstance();
                npc.start(c, 9200000);
            } else if (splitted[0].equals("@mia")) {
                NPCScriptManager npc = NPCScriptManager.getInstance();
                npc.start(c, 9010002);   
            } else if (splitted[0].equals("@kite")) {
                c.getSession().write(MaplePacketCreator.useKite(c, splitted[1], 5080000, "hey"));
            } else if (splitted[0].equals("@test")) {
                c.getSession().write(MaplePacketCreator.useKite(c, splitted[1], 5080000, "hey"));
            } else if (splitted[0].equals("@storage")) {
                c.getPlayer().getStorage().sendStorage(c, 2080005);
            } else if (splitted[0].equals("@freemarket") || splitted[0].equals("@fm")) {
                if ((c.getPlayer().getHp() < 1)) {
                    mc.dropMessage("Not while dead.");
                    c.getSession().write(MaplePacketCreator.enableActions());
                } else if (c.getPlayer().getMapId() < 100000000 || c.getPlayer().getMapId() == 200090300) {
                    mc.dropMessage("You can't enter Free market from maple island");
                    c.getSession().write(MaplePacketCreator.enableActions());
                } else {
                    if ((c.getPlayer().getMapId() < 910000000) || (c.getPlayer().getMapId() > 910000022)) {
                        mc.dropMessage(" Voice: Ok ok, let me warp you there.");
                        c.getSession().write(MaplePacketCreator.enableActions());
                        int quan = itemQuantity(c, 2100067);
                        gainItem(c, 2100067, (short) -quan);
                        MapleMap to;
                        MaplePortal pto;
                        to = ChannelServer.getInstance(c.getChannel()).getMapFactory().getMap(910000000, c.getPlayer().getWorld());
                        c.getPlayer().saveLocation(SavedLocationType.FREE_MARKET);
                        pto = to.getPortal("out00"); // or st00?
                        c.getPlayer().changeMap(to, pto);
                    } else { 
                        mc.dropMessage("You are already in the Free Market Entrance.");
                        c.getSession().write(MaplePacketCreator.enableActions());
                    }
                }
            } else if (splitted[0].equals("@str")) {
                int up;
                up = Integer.parseInt(splitted[1]);
                MapleCharacter player = c.getPlayer();
                if ( player.getRemainingAp() < up ||  player.getRemainingAp() < 0 || (player.getStr() + up) < 4 || player.getStr() + up > 32767) {
                    mc.dropMessage("Lol cheater, didn't think so!");
                } else {
                    player.setStr(player.getStr() + up);
                    player.setRemainingAp(player.getRemainingAp() - up);
                    player.updateSingleStat(MapleStat.AVAILABLEAP, player.getRemainingAp());
                    player.updateSingleStat(MapleStat.STR, player.getStr());
                }
            } else if (splitted[0].equals("@getbanned")) {
                c.getSession().write(MaplePacketCreator.blockMessage(StringUtil.joinStringFrom(splitted, 1)));
            } else if (splitted[0].equals("@fart")) {
                int size = 0;
                if (splitted[1] == null) size = 0;
                else size = Integer.parseInt(splitted[1]);
                int[] prices = new int[] {1000, 5000, 15000, 40000, 75000, 125000, 200000, 300000, 500000, 1000000};
                if (splitted[1] == null) size = 0;
                if (size > 0 && size <= 10) {
                    final int price = prices[size - 1];
                    final int finalz = (size * size * size);
                    if (c.getPlayer().getMeso() >= price) {
                        c.getPlayer().getMap().broadcastMessage(MaplePacketCreator.getChatText(cc.getId(), "hmmm", false, 1));
                        c.getPlayer().getMap().broadcastMessage(c.getPlayer(), MaplePacketCreator.facialExpression(c.getPlayer(), 3), false);
                        TimerManager.getInstance().schedule(new Runnable() {
                        @Override
                        public void run() {
                            cc.getMap().broadcastMessage(MaplePacketCreator.getChatText(cc.getId(), "rrrrrrrrrr", false, 1));
                            cc.getMap().broadcastMessage(cc, MaplePacketCreator.facialExpression(cc, 4), false);
                            TimerManager.getInstance().schedule(new Runnable() {
                                @Override
                                public void run() {
                                cc.getMap().broadcastMessage(MaplePacketCreator.getChatText(cc.getId(), "HRAAAAAA", false, 1));
                                cc.getMap().broadcastMessage(cc, MaplePacketCreator.facialExpression(cc, 5), false);
                                TimerManager.getInstance().schedule(new Runnable() {
                                    @Override
                                    public void run() {
                                        cc.getMap().broadcastMessage(MaplePacketCreator.getChatText(cc.getId(), "AAAAAAAAAAAAARGH", false, 1));
                                        cc.getMap().broadcastMessage(cc, MaplePacketCreator.facialExpression(cc, 15), false);
                                        cc.gainMeso(-price, true);
                                        Rectangle bounds = new Rectangle((int)cc.getPosition().getX() - (finalz / 2), (int)cc.getPosition().getY() - (finalz / 2), finalz, finalz);
                                        MapleStatEffect mse = new MapleStatEffect();
                                        mse.setSourceId(2111003);
                                        MapleMist mist = new MapleMist(bounds, cc, mse);
                                        cc.getMap().spawnMist(mist, 30000, false, true);
                                        }
                                    }, 5000);
                                }
                            }, 5000);
                            }
                        }, 5000);
                    } else {
                        mc.dropMessage("You don't have enough mesos");
                    }
                } else
                    mc.dropMessage("Please use it as @fart 1 - 10");
            } else if (splitted[0].equals("@accept")) {
                if (c.getPlayer().getAllianceInvited() != null) {
                    c.getPlayer().getAllianceInvited().addGuild(c, c.getPlayer().getGuildId());
                    c.getPlayer().setAllianceInvited(null);
                }
            } else if (splitted[0].equals("@decline")) {
                if (c.getPlayer().getAllianceInvited() != null) {
                    c.getPlayer().setAllianceInvited(null);
                }
            } else if (splitted[0].equals("@online")) {
                mc.dropMessage("Characters connected to channel " + c.getChannel() + ":");
                Collection<MapleCharacter> chrs = c.getChannelServer().getInstance(c.getChannel()).getPlayerStorage().getAllCharacters();
                for (MapleCharacter chr : chrs) {
                    if (!chr.isGM()) {
                        mc.dropMessage(chr.getName() + " at map ID: " + chr.getMapId());
                    } else {
                        mc.dropMessage(chr.getName() + " (GM)");
                    }
                }
                mc.dropMessage("Total characters on channel " + c.getChannel() + ": " + chrs.size());
            } else if (splitted[0].equalsIgnoreCase("@" + c.getPlayer().getName())) {
                c.getPlayer().getMap().broadcastMessage(MaplePacketCreator.getChatText(c.getPlayer().getId(), "Meh, i love ChickenMS <3 ima use @vote all the time!", c.getPlayer().isGM(), 0));
            } else if (splitted[0].equals("@ranking")) {
                try {
                    int int1 = 0;
                    int int2 = 0;
                    Connection con = DatabaseConnection.getConnection();
                    PreparedStatement ps = con.prepareStatement("SELECT * FROM characters WHERE job >= ? AND job <= ? AND gm = 0 ORDER BY level DESC LIMIT 10");
                    if (splitted.length == 1) {
                        mc.dropMessage("@ranking <job>, as job = warrior/magician/bowman/thief/pirate/beginner/me/all");
                        return;
                    } else if (splitted[1].equals("warrior")) {
                        int1 = 100;
                        int2 = 132;
                    } else if (splitted[1].equals("magician")) {
                        int1 = 200;
                        int2 = 232;
                    } else if (splitted[1].equals("bowman")) {
                        int1 = 300;
                        int2 = 322;
                    } else if (splitted[1].equals("thief")) {
                        int1 = 400;
                        int2 = 422;
                    } else if (splitted[1].equals("pirate")) {
                        int1 = 500;
                        int2 = 522;
                    } else if (splitted[1].equals("beginner")) {
                        int1 = 0;
                        int2 = 0;
                    } else if (splitted[1].equals("all")) {
                        int1 = 0;
                        int2 = 522;
                    } else if (splitted[1].equals("me")) {
                        ps = con.prepareStatement("SELECT name FROM characters ORDER BY level DESC");
                        ResultSet rs = ps.executeQuery();
                        int i = 0;
                        int lol = 0;
                        while (rs.next()) {
                            i++;
                            if (rs.getString("name").equals(c.getPlayer().getName())) {
                                lol = i;
                            }
                        }
                        mc.dropMessage("You are currently ranked " + lol);
                        ps.close();
                        rs.close();
                        return;
                    } else {
                        mc.dropMessage("I don't recognize that job, make sure you use lower-case");
                        return;
                    }
                    ps.setInt(1, int1);
                    ps.setInt(2, int2);
                    ResultSet rs = ps.executeQuery();
                    int i = 0;
                    mc.dropMessage("These are the top 10 ChickenMS players:");
                    while (rs.next()) {
                        i++;
                        mc.dropMessage(i + ") " + rs.getString("name") + ", level " + rs.getInt("level"));
                    }
                    ps.close();
                    rs.close();
                } catch (SQLException e) {
                    mc.dropMessage("Unknown error, please report this to Bassoe");
                }
            } else if (splitted[0].equals("@int")) {
                int up;
                up = Integer.parseInt(splitted[1]);                   
                MapleCharacter player = c.getPlayer();
                if ( player.getRemainingAp() < up ||  player.getRemainingAp() < 0 || (player.getInt() + up) < 4 || player.getInt() + up > 32767) {
                    mc.dropMessage("Lol cheater, didn't think so!");
                } else {
                    player.setInt(player.getInt() + up);
                    player.setRemainingAp(player.getRemainingAp() - up);
                    player.updateSingleStat(MapleStat.AVAILABLEAP, player.getRemainingAp());
                    player.updateSingleStat(MapleStat.INT, player.getInt());
                }
            } else if (splitted[0].equals("@dex")) {
                int up;
                up = Integer.parseInt(splitted[1]);
                MapleCharacter player = c.getPlayer();
                if ( player.getRemainingAp() < up ||  player.getRemainingAp() < 0 || (player.getDex() + up) < 4 || player.getDex() + up > 32767) {
                    mc.dropMessage("Lol cheater, didn't think so!");
                } else {
                    player.setDex(player.getDex() + up);
                    player.setRemainingAp(player.getRemainingAp() - up);
                    player.updateSingleStat(MapleStat.AVAILABLEAP, player.getRemainingAp());
                    player.updateSingleStat(MapleStat.DEX, player.getDex());
                }
            } else if (splitted[0].equals("@luk")) {
                int up;
                up = Integer.parseInt(splitted[1]);
                MapleCharacter player = c.getPlayer();
                if ( player.getRemainingAp() < up ||  player.getRemainingAp() < 0 || (player.getLuk() + up) < 4 || player.getLuk() + up > 32767) {
                    mc.dropMessage("Lol cheater, didn't think so!");
                } else {
                    player.setLuk(player.getLuk() + up);
                    player.setRemainingAp(player.getRemainingAp() - up);
                    player.updateSingleStat(MapleStat.AVAILABLEAP, player.getRemainingAp());
                    player.updateSingleStat(MapleStat.LUK, player.getLuk());
                }
            } else if (splitted[0].equals("@partner")) {   
                if (c.getChannelServer().getPlayerStorage().getCharacterByName(splitted[1]) != null) {
                    c.getPlayer().setPartnerName(splitted[1]);
                } else {
                    mc.dropMessage("That character could not be found");
                }
            } else if (splitted[0].equals("@vote")) {
                String text = "All vote for ChickenMS! use @vote";
                c.getPlayer().getMap().broadcastMessage(MaplePacketCreator.getChatText(c.getPlayer().getId(), text, false, 0));
                mc.dropMessage("http://chickenvote.kicks-ass.net - This command didnt vote, it just told the link");
            } else if (splitted[0].equals("@commands")) {
                mc.dropMessage("The player Commands are:");
                mc.dropMessage("@vote, @freemarket, @str, @int, @dex, @luk, @save, @version, @help, @spinel, @cody, @storage, @gms, @getbanned");
            } else if (splitted[0].equals("@makehome")) {
                if (c.getPlayer().getMeso() >= 1000000) {
                    if (c.getPlayer().getMapId() < 910000001 || c.getPlayer().getMapId() > 910000100) {
                        c.getPlayer().setHome(c.getPlayer().getMapId());
                        c.getPlayer().gainMeso(-1000000, true);
                    }
                } else
                    mc.dropMessage("You do not have 1.000.000 mesos");
            } else if (splitted[0].equals("@home")) {
                MapleMap home = c.getChannelServer().getMapFactory().getMap(c.getPlayer().getHome(), c.getPlayer().getWorld());
                if (c.getPlayer().getHome() > 0)
                    c.getPlayer().changeMap(home, home.getPortal(0));
                else
                    mc.dropMessage("You don't have a home yet!");
            } else if (splitted[0].equals("@save")) {
                c.getPlayer().saveToDB(true);
                mc.dropMessage("Saved.");
            } else if (splitted[0].equals("@version")) {
                mc.dropMessage("This is version 17.2 Of ChickenMS, i am fixing as much bugs as possible");
            } else if (splitted[0].equals("@scrollshop")) {
                MapleShopFactory sfact = MapleShopFactory.getInstance();
                MapleShop shop = sfact.getShop(153);
                shop.sendShop(c);
            } else if (splitted[0].equals("@gms")) {
                mc.dropMessage("A lot, just remember AdminBas");
            } else if (splitted[0].equals("@help")) {
                if (splitted.length != 2) {
                    mc.dropMessage("Syntax: The following commands will help you:");
                    mc.dropMessage("@help commands");
                    mc.dropMessage("@help report");
                    mc.dropMessage("@help job");
                    mc.dropMessage("@help skills");
                    mc.dropMessage("@help ap");
                    mc.dropMessage("@help buying");
                    mc.dropMessage("@help rebirth");
                    mc.dropMessage("@help pvp");
                } else if (splitted[1].equals("commands")) {
                    mc.dropMessage("Commands:");
                    mc.dropMessage("@spinel, @cody, @storage, @str, @int, @dex, @luk, @save, @help");
                    mc.dropMessage("@vote, @online, @version, @rebirth, @mia, @getbanned, @freemarket, @fm");
                    mc.dropMessage("@clearinv, @random, @ranking, @fart, @makehome, @home");
                } else if (splitted[1].equals("report")) { 
                    mc.dropMessage("How to report:");
                    mc.dropMessage("Right click the player you want to report");
                    mc.dropMessage("Then click the drop down menu and select why yo want to report the player"); 
                    mc.dropMessage("You may include a chat log for the Gm's to review just tick the box");
                } else if (splitted[1].equals("job")) { 
                    mc.dropMessage("Changing jobs:");
                    mc.dropMessage("To change your job simply do it like in normal MapleStory");
                    mc.dropMessage("Now when you hit 30 and higher you may use cody (use @cody)");
                } else if (splitted[1].equals("skills")) {
                    mc.dropMessage("All About Skills:");
                    mc.dropMessage("Every skill works.");
                } else if (splitted[1].equals("ap")) {
                    mc.dropMessage("All About Ability(Ap):");
                    mc.dropMessage("To add ap faster use the @str etc.. commands(it is not free sp)");
                    mc.dropMessage("The maximum Ap you may have is 32,767");
                    mc.dropMessage("To reset your stats use @str -20 for example");
                } else if (splitted[1].equals("buying")) {
                    mc.dropMessage("Where to buy stuff:");
                    mc.dropMessage("1 word: hengki - go to free market and you will see");
                } else if (splitted[1].equals("rebirth")) { 
                    mc.dropMessage("All about the rebirth Process:");
                    mc.dropMessage("@rebirth");
                    mc.dropMessage("You must be level 200");
                    mc.dropMessage("Have fun!");
                } else if (splitted[1].equals("pvp")) { 
                    mc.dropMessage("PVP stand for Player verus Player");
                    mc.dropMessage("Since we find this a noob function, we don't have it");
                } else {
                    mc.dropMessage("Try another term");
                }     
            }               
        }
        
        public int itemQuantity(MapleClient c, int itemid) {
                MapleInventoryType type = MapleItemInformationProvider.getInstance().getInventoryType(itemid);
                MapleInventory iv = c.getPlayer().getInventory(type);
                int possesed = iv.countById(itemid);
                return possesed;
        }
        
        @SuppressWarnings("static-access")
	public void gainItem(MapleClient c, int id, short quantity) {
		if (quantity >= 0) {
			StringBuilder logInfo = new StringBuilder(c.getPlayer().getName());
			logInfo.append(" received ");
			logInfo.append(quantity);
			logInfo.append(" from a scripted PlayerInteraction (");
			logInfo.append(this.toString());
			logInfo.append(")");
                        if (id >= 5000000 && id <= 5000060) {
                            int petId = MaplePet.createPet(id);
                            MapleInventoryManipulator.addById(c, id, quantity, logInfo.toString(), c.getPlayer().getName(), petId);
                        } else {
                            MapleInventoryManipulator.addById(c, id, quantity, logInfo.toString());
                        }
		} else {
                    if (id >= 5000000 && id <= 5000060) {
                        MaplePet.deletePet(id, c);
                        MapleInventoryManipulator.removeById(c, MapleInventoryType.CASH, id, (short) 1, false, false);
                        c.getSession().write(MaplePacketCreator.enableActions());
                    } else {
			MapleInventoryManipulator.removeById(c, MapleItemInformationProvider.getInstance().getInventoryType(id), id, -quantity, true, false);
                    }
		}
		c.getSession().write(MaplePacketCreator.getShowItemGain(id,quantity, true));
	}

        public int getRandom(int length) {
            return (int) Math.floor(Math.random() * length) + 1;
        }
        
	@Override
	public CommandDefinition[] getDefinition() {
		return new CommandDefinition[] {
			new CommandDefinition("spinel", "", "Opens spinel from anywhere", 0),
            new CommandDefinition("cody", "", "Opens cody from anywhere", 0),
            new CommandDefinition("storage", "", "Opens storage from anywhere", 0),
            new CommandDefinition("str", "", "add your stats very fast", 0),
            new CommandDefinition("int", "", "add your stats very fast", 0),
            new CommandDefinition("dex", "", "add your stats very fast", 0),
            new CommandDefinition("luk", "", "add your stats very fast", 0),
            new CommandDefinition("save", "", "save your data", 0),
            new CommandDefinition("scrollshop", "", "open scrollshop from anywhere", 0),
            new CommandDefinition("gms", "", "Current GMs for this server", 0),
            new CommandDefinition("help", "", "about our server", 0),
            new CommandDefinition("vote", "", "help ChickenMS lol", 0),
            new CommandDefinition("online", "", "Check who is online", 0),
            new CommandDefinition("team", "", "Set yourself a team", 0),
            new CommandDefinition("version", "", "what version is ChickenMS?", 0),
            new CommandDefinition("rebirth", "", "reborn!!", 0),
            new CommandDefinition("mia", "", "max your skills", 0),
            new CommandDefinition("kite", "", "max your skills", 0),
            new CommandDefinition("test", "", "resets the air", 0),
            new CommandDefinition("stopms", "", "stop your maplestory", 0),
            new CommandDefinition("getbanned", "", "lulz", 0),
            new CommandDefinition("freemarket", "", "go to free market", 0),
            new CommandDefinition("fm", "", "go to free market", 0),
            new CommandDefinition("clearinv", "", "clear your slots", 0),
            new CommandDefinition("partner", "", "clear your slots", 0),
            new CommandDefinition("random", "", "say some random shit", 0),
            new CommandDefinition("ranking", "", "who is the strongest mapler", 0),
            new CommandDefinition("fart", "", "lulz", 0),
            new CommandDefinition("accept", "", "accept", 0),
            new CommandDefinition("decline", "", "decline", 0),
            new CommandDefinition("makehome", "", "create a home", 0),
            new CommandDefinition("home", "", "warp to your home", 0),
            new CommandDefinition("@*", "", "Lol?", 0),
		
		};
	}

}
